<?php
//var_dump($data);
?>
<?php
require_once WEB_ROOT_FOLDER.'views/header.php';
if(isset($_SESSION['username']) && isset($_SESSION['access_level']) && ($_SESSION['access_level'] > 0)){
?>
<fieldset class="col_12 column">
    <legend>Zarządaj komentarzami, edytuj i dodwaj komentarze</legend>
    <?php
    if(isset($data['page']['content']) && is_array($data['page']['content'])){
        ?>
    <h4>Edytuj komentarz</h4>
    <form method="post" action="<?php echo SITE_ROOT;?>zarzadzaj-kontem/aktualizuj-komentarz.html">
    <?php
    }
    else {
      ?>
    <h4>Dodaj komentarz</h4>
    <form method="post" action="<?php echo SITE_ROOT;?>zarzadzaj-kontem/wstaw-komentarz.html">
    <?php
    }
    ?>
        <?php
        if(isset($data['page']['content']['0']['0'])){
            ?>
        <input type="hidden" name="id" value="<?php echo $data['page']['content']['0']['0'];?>">
        <?php
        }
        ?>
        <?php
        if(isset($data['page']['csrf_token'])){
            ?>
        <input type="hidden" name="csrf_token" value="<?php echo $data['page']['csrf_token'];?>">
        <?php
        }
        ?>
        <?php
        if(isset($data['page']['content']['0']['1'])){
            ?>
        <label class="col_12 column" for="page_name">Edytuj stronę<span class="right">Do tej strony jest przypisana dany komentarz</span></label><br>
        <?php
        }
        else {
            ?>
        <label class="col_12 column" for="page_name">Dodaj stronę<span class="right">Do tej strony jest przypisana dany komentarz</span></label><br>
        <?php
        }
        ?>
        <select class="col_12 column" name="page_name" id="page_name" required autofocus>
            <?php
            if(!isset($data['page']['content']['0']['1'])){
                ?>
            <option selected="selected">Wybierz stronę</option>
            <?php
            }
            ?>
            <?php
            if(isset($data['page']['page']) && is_array($data['page']['page'])){
                foreach($data['page']['page'] as $key => $value){
                    if(isset($value['0']) && isset($value['0'])){
                        if(isset($data['page']['content']['0']['1']) && ($data['page']['content']['0']['0'])){
                            ?>
            <option value="<?php echo $value['0'];?>" selected="selected"><?php echo $value['1'];?></option>
            <?php
                        }
                        else {
                            ?>
            <option value="<?php echo $value['0'];?>"><?php echo $value['1'];?></option>
            <?php
                        }
                    }
                }
            }
            ?>
        </select><br>
        <?php
        if(isset($data['page']['content']['0']['2'])){
            ?>
        <label for="comment_text" class="col_12 column">Edytuj komentarz<span class="right">Wpisz tekst Twojego komentarza</span></label><br>
        <textarea class="col_12 column" name="comment_text" id="comment_text" required autofocus><?php echo $data['page']['content']['0']['2'];?></textarea><br><br>
        <?php
        }
        else {
            ?>
        <label for="comment_text" class="col_12 column">Dodaj komentarz<span class="right">Wpisz tekst Twojego komentarza</span></label><br>
        <textarea class="col_12 column" name="comment_text" id="comment_text" placeholder="Wpisz tutaj komentarz" required autofocus></textarea><br><br>
        <?php
        }
        ?>
        <?php
        if(isset($data['page']['content']) && is_array($data['page']['content'])){
          ?>
        <input type="submit" name="submit" id="submit" value="Edytuj komentarz">
        <?php
        }
        else {
            ?>
        <input type="submit" name="submit" id="submit" value="Dodaj komentarz">
        <?php
        }
        ?>
    </form>
</fieldset>
<?php
}
require_once WEB_ROOT_FOLDER.'views/footer.php';
?>

